﻿
    namespace Excel {
        export interface WorkBook {
            WorkSheets: WorkSheet[];
            Styles: Styles;
            ActiveSheetIndex?: number;
        }
        export interface WorkSheet {
            SheetName: string;
            ExpandedColumnCount: number;
            ExpandedRowCount: number;
            DefaultColumnWidth: number;
            DefaultRowHeight: number;
            ActiveCell?: CellPoint;
            Rows: Rows;
            Columns?: Columns;
            Merges: Merge[];
        }
        export interface Merge {
            StartCell: CellPoint
            EndCell: CellPoint
        }
        export interface CellPoint {
            RowNum: number;
            CellNum: number;
        }
        export interface Columns {
            [index: number]: Column;
        }
        export interface Column {
            Width?: number;
        }
        export interface Rows {
            [index: string]: Row;
        }
        export interface Row {
            Height?: number;
            Cells?: Cells;
        }
        export interface Cells {
            [index: string]: Cell;
        }
        export interface Cell {
            StyleID?: string;
            Data?: Data;
        }
        export interface Data {
            Type: string;
            Value: string;
        }
        export interface Styles {
            [index: string]: Style;
        }
        export interface Style {
            Alignment?: Alignment;
            Borders?: Borders;
            Font?: Font;
        }
        export interface Alignment {
            Vertical?: string;
            Horizontal?: string;
        }
        export interface Borders {
            Border?: Border;
            BorderTop?: Border;
            BorderBottom?: Border;
            BorderLeft?: Border;
            BorderRight?: Border;
        }
        export interface Border {
            LineStyle: string;
            Weight: number;
            Color: string;
        }
        export interface Font {
            FontName?: string;
            Size?: number;
            Color?: string;
        }
        export interface Location {
            Left: number;
            Top: number;
        }
        export interface Point {
            X: number;
            Y: number;
        }
        export interface Size {
            Width: number;
            Height: number;
        }
 
        export interface Copy {
            Rows?: Rows;
            Merge: Merge;
        }
 
        export class PubFun {
            static server(url:string,data: any, succ: Function, fail: Function = null, error: Function = null) {
                $.ajaxSettings.url = url;
                $.ajaxSettings.type = "POST";
                $.ajaxSettings.dataType = "json";
                $.ajaxSettings.data = data,
                $.ajaxSettings.success = function (rdata) {
                    succ && succ(rdata);
                };
                $.ajaxSettings.error = function (xhr) {
                    error && error(xhr);
                };
                $.ajax();
            }
            static deserializeJson(json: any, _this: any) {
                if (!_this) _this = {};
                for (var prop in json) {
                    if (!json.hasOwnProperty(prop)) continue;
                    if (typeof json[prop] === 'object') PubFun.deserializeJson(json[prop], _this[prop]);
                    else _this[prop] = json[prop];
                }
            }

            static maxInArray(a: number[]) {
                if (a) {
                    let max: number = a[0];
                    for (let i = 1; i < a.length; i++) {
                        if (a[i] > max) max = a[i];
                    }
                    return max;
                }
                return null;
            }
            static minInArray(a: number[]) {
                if (a) {
                    let min: number = a[0];
                    for (let i = 1; i < a.length; i++) {
                        if (a[i] < min) min = a[i];
                    }
                    return min;
                }
                return null;
            }
            //将26进制转10进制  
            static convertNum(str: string): number {
                var n = 0;
                var s = str.match(/./g);//求出字符数组  
                var j = 0;
                for (var i = str.length - 1, j = 1; i >= 0; i-- , j *= 26) {
                    var c = s[i].toUpperCase();
                    if (c < 'A' || c > 'Z') return 0;
                    n += (c.charCodeAt(0) - 64) * j;
                }
                return n;
            }

            //将10进制转26进制  
            static convert26(num: number): string {
                var str = "";
                while (num > 0) {
                    var m = num % 26;
                    if (m == 0) m = 26;
                    str = String.fromCharCode(m + 64) + str;
                    num = (num - m) / 26;
                }
                return str;
            }
            static insertAfter(newEl: any, targetEl: any) {
                var parentEl = targetEl.parentNode;

                if (parentEl.lastChild == targetEl) {
                    parentEl.appendChild(newEl);
                } else {
                    parentEl.insertBefore(newEl, targetEl.nextSibling);
                }
            }
            static jsonCopy(a: any): any {
                if (a) return JSON.parse(JSON.stringify(a));
                return null;
            }
            static jsonEqual(a: any, b: any): boolean {
                return JSON.stringify(a) == JSON.stringify(b)
            }
            static jsonMerge(json: any, newjson: any): any {
                let a: any = {};
                for (var prop in json) {
                    if (json[prop] == null) a[prop] = null;
                    else if (typeof json[prop] === 'object') a[prop]= PubFun.jsonMerge(a[prop], json[prop]);
                    else a[prop] = json[prop];
                }
                for (var prop in newjson) {
                    if (newjson[prop] == null) a[prop] = null;
                    else  if (typeof newjson[prop] === 'object') a[prop] = PubFun.jsonMerge(a[prop], newjson[prop]);
                    else a[prop] = newjson[prop];
                }
                return a;
            }
            static max(a: number, b: number): number {
                return a >= b ? a : b;
            }
            static min(a: number, b: number): number {
                return a < b ? a : b;
            }
            static offset(node: any): Location {
                var top = node.offsetTop;
                var left = node.offsetLeft;
                while (node.offsetParent) {
                    node = node.offsetParent;
                    if (window.navigator.userAgent.indexOf('MSTE 8') > -1) {
                        top += node.offsetTop;
                        left += node.offsetLeft;
                    } else {
                        top += node.offsetTop + node.clientTop;
                        left += node.offsetLeft + node.clientLeft;
                    }
                }
                return { Left: left, Top: top };
            }
            //将rgb()格式颜色转换成大写十六机制字符串（#C0C0C0），如果已经是十六进制则直接输出
            static RGBtoHEX(str) {
                let toHex=(N:any)=> {
                    if (N == null) return "00";
                    N = parseInt(N); if (N == 0 || isNaN(N)) return "00";
                    N = Math.max(0, N); N = Math.min(N, 255); N = Math.round(N);
                    return "0123456789ABCDEF".charAt((N - N % 16) / 16) + "0123456789ABCDEF".charAt(N % 16);
                }
                if (str.substring(0, 3) == 'rgb') {
                    var arr = str.split(",");
                    var r = arr[0].replace('rgb(', '').trim();
                    var g = arr[1].trim();
                    var b = arr[2].replace(')', '').trim();
                    return "#" + toHex(r) + toHex(g) + toHex(b);
                }
                else {
                    return str;
                }
            }
            static getButton (key:string,icon: string, onClick: Function = null, disabled: boolean = false, btText: string = "") {
                return React.createElement(antd.Button, { key: key, disabled: disabled, onClick: onClick }, [
                    React.createElement("i" as any, { key: "icon", className: icon, style: { fontSize: 16, color: disabled ? "#ddd" : "#000" } }), btText
                ])
            }
            static getMenuItem (key: string, className: string, btText: string = "", disabled: boolean = false) {
                return React.createElement(antd.Menu.Item, { key: key }, [
                    React.createElement("i" as any, { key: "icon", disabled: disabled, className: className, style: { fontSize: 16, paddingRight: 5 } }),
                    btText
                ]);
            }
        }
    }

    var excelData: Excel.WorkBook = {
        WorkSheets: [{
                SheetName: "111",
                ExpandedColumnCount: 10,
                ExpandedRowCount: 10,
                DefaultColumnWidth: 80,
                DefaultRowHeight: 18,
                Merges: [],
                Columns: {
                    4: {
                        Width: 200
                    }
                },
                Rows: {
                    2: {
                        Height:50,
                        Cells: {
                            4: {
                                Data: {
                                    Type: "String",
                                    Value: "12333"
                                }
                            },
                            8: {
                                Data: {
                                    Type: "String",
                                    Value: "12333"
                                }
                            }
                        }
                    }
                }
            },
            {  
                SheetName: "222",
                ExpandedColumnCount: 10,
                ExpandedRowCount: 10,
                DefaultColumnWidth: 80,
                DefaultRowHeight: 18,
                Merges: [],
                Rows: {
                    5: {
                        Cells: {
                            2: {
                                StyleID: "1",
                                Data: {
                                    Type: "String",
                                    Value: "12333"
                                }
                            },
                            7: {
                                Data: {
                                    Type: "String",
                                    Value: "12333"
                                }
                            }
                        }
                    }
                }
                
            }
        ],
        Styles: {
            "Default": {
                Alignment: {
                    Vertical: "Bottom"
                },
                Font: {
                    FontName: "宋体",
                    Size: 11,
                    Color: "#000000"
                }
            },
            "1": {
                Borders: { Border: { LineStyle: "solid", Weight: 1, Color:"#FF0000" } }
            }
        }
    };





